package model.objects;

import java.awt.Graphics;
import java.awt.image.ImageObserver;
import java.util.Observer;

import javax.swing.JPanel;

import model.general.Location;

public class FunnyObject extends Sprites{
	private String[] imgChange;
	private int count = 0;
	private int currentImage= 0;

	public FunnyObject(Location location, String srcImgLeft, String srcImgRight, JPanel pnl,String[] imgChange) {
		super(location, srcImgLeft, srcImgRight, pnl);
		this.imgChange = imgChange;
		System.out.println("lenght mang bubble = " + imgChange.length);
	}
	
	public void update(){
		if (imgChange.length > 0) {
			if (count > 32000) {
				count = 0;
			}
			if (count % 20 == 0) {
				nextImg();
			}
			count++;
		}
	}
	
	public void nextImg(){
		if ((currentImage + 1) >= imgChange.length) {
			currentImage = 0;
		}else {
			currentImage += 1;
		}
		img = loadImage.getbufferImage(imgChange[currentImage]);
	}
	
	
	
	public String[] getImgChange() {
		return imgChange;
	}

	public void setImgChange(String[] imgChange) {
		this.imgChange = imgChange;
	}

	public void show(Graphics g){
		g.drawImage(img,location.getX(),location.getY(),null);
	}
	
}
